<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/6/7 0007
  Time: 21:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%String path = request.getContextPath();%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!-- Job List Start -->
<c:forEach items="${personInfoList}" var="personInfo">
    <a class="job-list">
        <div class="salary-type col-auto order-sm-3">
            <div class="btns">
                <button type="button" id="read" onclick="javascript:window.location.href='<%=path%>/web/news/personNews/read?id=${personInfo.id}'" class="badge badge-info">查看</button>
                <button type="button" id="del" data-id="${personInfo.id}" class="badge badge-danger">删除</button>
            </div>
        </div>
        <div class="content col">
            <h6 class="title" title="${personInfo.content}" id="content${personInfo.id}">${personInfo.content}</h6>
            <ul class="meta">
                <c:if test="${personInfo.isRead eq true}">
                    <li>已读</li>
                </c:if>
                <c:if test="${personInfo.isRead ne true}">
                    <li><strong class="text-primary">未读</strong></li>
                </c:if>
                <li><strong class="text-primary">来自:</strong></li>
                <li>${personInfo.resourcePerson.name}</li>
                <li>${personInfo.timeStr}</li>
            </ul>
        </div>
    </a>
</c:forEach>
<!-- Job List Start -->
<!-- Pagination Start -->
<ul class="pagination pagination-center mt-5">

    <li class="page-item"><a class="page-link" id="prePage" data-id="${pageInfo.pageNum-1}"><i class="fa fa-angle-left"></i></a></li>

    <c:if test="${pageInfo.pages>=5}">
        <c:if test="${pageInfo.pageNum>=3 && pageInfo.pageNum<=pageInfo.pages-2}">
            <c:forEach begin="${pageInfo.pageNum-2}" end="${pageInfo.pageNum+2}" var="stat">
                <c:if test="${stat eq pageInfo.pageNum}">
                    <li class="page-item active"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
                </c:if>
                <c:if test="${stat ne pageInfo.pageNum}">
                    <li class="page-item"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
                </c:if>
            </c:forEach>
        </c:if>
        <c:if test="${pageInfo.pageNum<3}">
            <c:forEach begin="1" end="5" var="stat">
                <c:if test="${stat eq pageInfo.pageNum}">
                    <li class="page-item active"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
                </c:if>
                <c:if test="${stat ne pageInfo.pageNum}">
                    <li class="page-item"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
                </c:if>
            </c:forEach>
        </c:if>
        <c:if test="${pageInfo.pageNum>pageInfo.pages-2}">
            <c:forEach begin="${pageInfo.pages-4}" end="${pageInfo.pages}" var="stat">
                <c:if test="${stat eq pageInfo.pageNum}">
                    <li class="page-item active"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
                </c:if>
                <c:if test="${stat ne pageInfo.pageNum}">
                    <li class="page-item"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
                </c:if>
            </c:forEach>
        </c:if>
    </c:if>
    <c:if test="${pageInfo.pages<5}">
        <c:forEach begin="1" end="${pageInfo.pages}" var="stat">
            <c:if test="${stat eq pageInfo.pageNum}">
                <li class="page-item active"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
            </c:if>
            <c:if test="${stat ne pageInfo.pageNum}">
                <li class="page-item"><a class="page-link" id="page${stat}" data-id="${stat}">${stat}</a></li>
            </c:if>
        </c:forEach>
    </c:if>

    <li class="page-item"><a class="page-link" id="nextPage" data-id="${pageInfo.pageNum+1}"><i class="fa fa-angle-right"></i></a></li>

</ul>
<!-- Pagination End -->


<script type="text/javascript" src="<%=path%>/assets/js/vendor/jquery-3.4.1.min.js"></script>
<script type="text/javascript">
    $(function () {
        $(function () {
            var intros = $("h6[id^=content]");
            $.each(intros,function () {
                if($(this).html().length>10){
                    $(this).html($(this).html().substring(0,10)+"...");
                }
            });
        });
        function getValue(pageNum){
            $.ajax({
                url:"<%=path%>/web/news/personNewsData",
                type:"post",
                data:"pageNum="+pageNum,
                success:function (data) {
                    $(".job-list-wrap").html(data);
                }
            });
        }
        $.each($("a[id^=page]"),function () {
            $(this).on("click",$(".job-list-wrap"),function () {
                var pageNum = $(this).attr("data-id");
                getValue(pageNum);
            })
        });
        $("#prePage").on("click",$(".job-list-wrap"),function () {
            var pageNum = $("#prePage").attr("data-id");
            if(pageNum<=0){
                pageNum = 1;
            }
            getValue(pageNum);
        });
        $("#nextPage").on("click",$(".job-list-wrap"),function () {
            var pageNum = $("#nextPage").attr("data-id");
            if(pageNum>${pageInfo.pages}){
                pageNum = ${pageInfo.pages};
            }
            getValue(pageNum);
        });


        var del = $("button[id=del]");
        $.each(del,function () {
            $(this).on("click",$(".job-list-wrap"),function () {
                var that = $(this);
                var data_id = $(this).attr("data-id");
                $.ajax({
                    url:"<%=path%>/web/news/personNews/del",
                    data:"id="+data_id,
                    async:false,
                    success:function (mes) {
                        if(mes=='1'){
                            that.parent().parent().parent().remove();
                        }
                    }
                });
            });
        });
    });
</script>

